class_name Enemy
extends Area2D

signal hit_player

@onready var animation_player: AnimationPlayer = $AnimationPlayer

var move_direction := Vector2.DOWN:
	set(v):
		move_direction = v.normalized()

var move_speed: float = 150


func _physics_process(delta: float) -> void:
	if animation_player.current_animation == "idle":
		position += move_direction * move_speed * delta


func _on_visible_on_screen_notifier_2d_screen_exited():
	pass


func _on_body_entered(body: Node2D) -> void:
	if body.name == "Player":
		hit_player.emit()
		Game.score -= floor(Game.score * 0.3)
		animation_player.play("boom")
		await animation_player.animation_finished
		queue_free()



func _on_area_entered(area: Area2D) -> void:
	if area is Bullet:
		Game.score += 1
		animation_player.play("boom")
		await animation_player.animation_finished
		queue_free()
